package simulacao.cenario;

import javafx.scene.CustomNode;
import javafx.scene.Group;
import javafx.scene.Node;
import javafx.scene.image.ImageView;
import javafx.scene.input.MouseEvent;
import javafx.scene.paint.Color;
import javafx.scene.paint.RadialGradient;
import javafx.scene.paint.Stop;
import javafx.scene.shape.Rectangle;
import javafx.scene.image.Image;
import simulacao.SimulationView;

/**
 * @author Marcello Willians
 */

public class BotaoTrocarCenario extends CustomNode {
    
    public-init var indice: Integer;
    public var selecionado: Boolean;
    public-init var imagem: Image;

    public-read def SIZE = 80;

    var btnx = 100 * indice + 20;
    var btny = 60;

    public override function create(): Node {

        Group {
            blocksMouse: true
            content: [

                Rectangle {
                    width: SIZE
                    height: SIZE
                    arcWidth: SIZE / 4
                    arcHeight: SIZE / 4
                    x: btnx
                    y: btny
                    fill: null
                    stroke: bind if (selecionado) then Color.YELLOW else Color.MEDIUMBLUE
                    strokeWidth: 4
                },

                Rectangle {
                    width: SIZE
                    height: SIZE
                    arcWidth: SIZE / 4
                    arcHeight: SIZE / 4
                    x: btnx
                    y: btny
                    fill: RadialGradient {
                        centerX: 0.5
                        centerY: 0.5
                        stops: [
                            Stop { offset: 0.0 color: Color.DARKBLUE },
                            Stop { offset: 0.8 color: Color.BLACK }
                        ]
                    }

                },

                ImageView {
                    x: (SIZE - imagem.width) / 2 + btnx
                    y: (SIZE - imagem.height) / 2 + btny
                    image: imagem
                }
            ]
            onMousePressed: function(ev: MouseEvent) {
                SimulationView.setarCenarioCorrente(indice);
            }
        }
    }
}